﻿@using Mozlite;
@using Mozlite.Common;
@using Mozlite.Common.Configuration
@using Mozlite.Web;
@using Mozlite.Web.Controls;
@using Mozlite.Web.UI.Areas.ControlPanel;

@*
    显示状态信息，包含关闭按钮，控制面板中使用
*@
@helper ShowDialogStatus(dynamic status)
{
    if (status.__Status != null)
    {
        if (status.__StatusType == true)
        {
        <div class="ui-state-error ui-corner-all" style="padding: 0 .7em;"> 
		    <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span> 
            @status.__Status
            </p>
	    </div>
        }
        else if (status.__StatusType == false)
        {
        <div class="box">
            <div class="status">
                @status.__Status
            </div>
            <div class="tcenter">
                <button onclick="parent.closeModal();parent.document.location.reload();">@Resources.GetString("Dialog.Closed", null, Routes.ControlPanel)</button>
            </div>
        </div>
        }
    }
}

@*
    显示更新状态，控制面板中使用
*@
@helper ShowStatus(dynamic status)
    {
        if (status.__Status != null)
        {
            if (status.__StatusType == true)
            {
	        <div class="ui-widget bm20">
		        <div class="ui-state-error ui-corner-all" style="padding: 0 .7em;"> 
			        <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span> 
                    @status.__Status
                    </p>
		        </div>
	        </div>
            }
            else if (status.__StatusType == false)
            {
           <div class="ui-widget bm20">
		        <div class="ui-state-highlight ui-corner-all" style="margin-top: 20px; padding: 0 .7em;"> 
			        <p><span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>
                    @status.__Status
                    </p>
		        </div>
	        </div>
            }
        }
}

@helper SetReadOnly(bool bSet = true)
    {
        if (bSet)
        {
         <text>readonly="readonly"</text>
        }
}

@helper ShowBoolean(bool bValue)
    {
        if (bValue)
        {
    <span class="ui-icon ui-icon-check"></span>
        }
        else
        {
    <span class="ui-icon ui-icon-close"></span>    
        }
}

@*
 分页
*@
@helper ShowPager(int pages, int pageIndex, string firstUrl, Func<int, string> urlFunction)
{
    if(pages > 1){
    <div class="box">
        <div class="ui-widget-header ui-corner-all pager">
            <a href="@firstUrl" class="first">@Resources.GetString("Pager.First")</a>  
            @if (pageIndex - 1 <= 1)
            { 
            <a href="@firstUrl" class="prev">@Resources.GetString("Pager.Prev")</a>
            }
            else
            {
            <a href="@urlFunction(pageIndex - 1)" class="prev">@Resources.GetString("Pager.Prev")</a>
            }
            <span title="@string.Format(Resources.GetString("Pager.Current"), pageIndex)" class="ui-button-text ui-button ui-widget ui-state-hover ui-corner-all ui-button-text-only"><span class="ui-button-text">@pageIndex</span></span>
            @if (pageIndex >= pages)
            {
            <a href="@urlFunction(pageIndex)" class="next">@Resources.GetString("Pager.Next")</a>
            }
            else
            {
            <a href="@urlFunction(pageIndex + 1)" class="next">@Resources.GetString("Pager.Next")</a>
            }
            <a href="@urlFunction(pages)" class="end">@Resources.GetString("Pager.End")</a>
        </div>
    </div>
    }
}

@*
  权限选项
*@
@helper ShowPermissionBooleanNullable(string permission, int roleID, bool? value)
{
    <input type="radio" name="@permission-@roleID" id="@permission-@roleID-0" @if(value == false){<text>checked="checked"</text>} value="False" />  
    <label for="@permission-@roleID-0">@Resources.GetString("PermissionOption.Deny", null, Routes.ControlPanel)</label>   
    <input type="radio" name="@permission-@roleID" id="@permission-@roleID-1" @if(value == null){<text>checked="checked"</text>} value="" />   
    <label for="@permission-@roleID-1">@Resources.GetString("PermissionOption.NotSet", null, Routes.ControlPanel)</label>   
    <input type="radio" name="@permission-@roleID" id="@permission-@roleID-2" @if(value == true){<text>checked="checked"</text>} value="True" />   
    <label for="@permission-@roleID-2">@Resources.GetString("PermissionOption.Allowed", null, Routes.ControlPanel)</label>   
}

@*
  分类显示
*@
@helper ShowCategories(Category category, int level = 0)
{
    foreach (var cat in category.Children)
    { 
        <tr>
            <td>├─@("─".Times(level))@(cat.CategoryName)</td>
            <td>@cat.Key</td>
            <td>@Resources.GetString(cat.ApplicationType)</td>
            <td>@cat.CreateDate.ToLocalDateTimeString()</td>
            <td>@cat.Threads</td>
            <td>
                <a href="javascript:void(0);" onclick="return openModal('@CUrls.DialogCategoryView?id=@cat.CategoryID', 500);">@Resources.GetString("Category.Edit")</a>
                <a href="javascript:void(0);" onclick="return send({action:'delete', did:@category.CategoryID});">@Resources.GetString("Category.Delete")</a>
            </td>
        </tr> 
        if (cat.Children != null)
        {
            @ShowCategories(cat, level + 1)
        }
    }   
}

@*
  论坛显示
*@
@helper ShowForums(Forum parent, int level = 0)
{
    foreach (var forum in parent.Children)
    { 
        <tr>
            <td>├─@("─".Times(level))@forum.ForumName</td>
            <td>@forum.Key</td>
            <td>@forum.CreateDate.ToLocalDateTimeString()</td>
            <td>@ShowBoolean(forum.IsVisiable)</td>
            <td>
                <a href="javascript:void(0);" onclick="return openModal('?id=@forum.ForumID', 500);">@Resources.GetString("Edit")</a>
                <a href="javascript:void(0);" onclick="return send({action:'delete', did:@forum.ForumID});">@Resources.GetString("Delete")</a>
            </td>
        </tr>  
        if (forum.Children != null)
        {
                @ShowForums(forum, level + 1)
        }
    }   
}

@*
  分类显示
*@
@helper ShowNavigators(Navigator parent, string theme, int level = 0)
{
    foreach (var navigator in parent.Children)
    { 
        <tr title="@navigator.Title">
            @if(string.IsNullOrEmpty(navigator.DisplayName))
            {
                <td>├─@("─".Times(level))@navigator.Title</td>
            }
            else
            {
                <td>├─@("─".Times(level))@(navigator.DisplayName)（@navigator.EnglishName）</td>
            }
            <td>@navigator.Key</td>
            <td>@navigator.NavigatorUrl</td>
            <td class="w80">
                <a href="javascript:void(0);" onclick="return openModal('@CUrls.GetDialogNavigatorUrl(theme)?id=@navigator.NavigatorID', 400);">@Resources.GetString("Edit")</a>
                <a href="javascript:void(0);" onclick="return send({action:'delete', did:@navigator.NavigatorID});">@Resources.GetString("Delete")</a>
            </td>
        </tr> 
        if (navigator.Children != null)
        {
            @ShowNavigators(navigator, theme, level + 1)
        }
    }   
}